/*
 * Copyright (c) 2018.
 * This file was written by Fancyears·Milos·Malvis @connor. Any question/bug you can't post to 1243093366@qq.com.
 * ALL RIGHTS RESERVED.
 */
package org.fancyears.renderer.jtable;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

/**
 * @author: Fancyears·Milos·Malvis
 * @CreateDate: 2018年12月4日 下午4:09:51
 * @Description:
 */

public class ButtonRenderer extends AbstractCellEditor implements TableCellRenderer, TableCellEditor {

	private static final long serialVersionUID = 1L;
	private JButton button = null;
	private JPanel panel;

	public ButtonRenderer(JButton jButton) {
		this.button = jButton;
		panel = new JPanel(new FlowLayout());
		button.setPreferredSize(new Dimension(24, 24));
//		panel.setSize(new Dimension(100, 24));
		panel.add(this.button);
		panel.setVisible(true);
		panel.setComponentZOrder(button, 0);
	}

	@Override
	public Object getCellEditorValue() {
		return null;
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
			int row, int column) {
		return button;
	}

	public void actionPerformed(ActionEvent e) {
		JOptionPane.showMessageDialog(null, "渲染器学期", "消息", JOptionPane.OK_OPTION);
	}

	@Override
	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
		return button;
	}
}
